*This file replicates regression results for Employment outcomes - Alternate measure of employment growth rate.
*The code used in this file is adapted from Baker, Bloom, and Davis (2016) to generate results related to environmental policy uncertainty.

******************************************
***************EMPLOYMENT
***Collapse to yearly data
clear all
use data/annual_firm_data 
gen period_code=year
tsset ticker_code period_code
gen one=1

foreach var of varlist one firm_intens sic_intens firm_sic_intens health_sic_intens health_firm_intens belo_intens h_firm_sic_intens {
	foreach var2 of varlist lepu leu lvix fed  fed_fore {
		qui gen `var2'_X_`var' = `var2'*`var'
		qui gen d`var2'_X_`var' = d.`var2'_X_`var'
	}
}

tsset 
gen demp2 = log(emp) - log(l.emp)
gen dlepu = d.lepu
gen dh_firm_sic_intens =d.h_firm_sic_intens
gen dfed = d.fed

gen SIC2=int(sic4/100)

merge m:1 year using data/04_Env_Policy_indices_annual
tsset

* Sectoral policy indices
gen env_firms=1 if inlist(sic3, 104, 109, 122, 131, 138, 241, 242, 491, 492) | inlist(SIC2, 1, 2, 37)
replace env_firms=0 if env_firms==.
foreach var in EPU_NB EP_NB {
replace `var'=0 if env_firms==0
}
drop _m
merge m:1 year using data/A_DP_FP_HP_Year
drop _m

gen def_firms = inlist(sic3, 348, 381, 871) 
foreach var in defense dp dpu {
replace `var'=0 if def_firms==0
}

gen health_firms=(sic3>=800&sic3<=809)
foreach var in health hp hpu{
replace `var'=0 if health_firms==0
}

gen fin_firms= (sic3>=600&sic3<=679) 
foreach var in fin_regulation fp fpu{
replace `var'=0 if fin_firms==0
}

tsset ticker_code period_code

foreach var in EPU_NB EP_NB dp dpu hp hpu fp fpu{
gen l`var'=log(`var')
gen dl`var'=d.l`var'
gen dl`var'_miss=(dl`var'==.)
replace dl`var'=0 if dl`var'_miss==1
}

egen noj=count(demp),by(ticker_code)
keep if noj>1

save data/etemp,replace

****** Alternate measure of employment growth rate (Table A-4)
reghdfe demp2 dlEPU_NB dlEP_NB dldpu dldp dlhpu dlhp dlfpu dlfp dlepu_X_h_firm_sic_intens dfed_X_h_firm_sic_intens, ab(ticker_code period_code) vce(cl ticker)

****************************************************************************************
